// 麻将游戏的网络消息
window.MJNetMsg = {
    send: {
        Login: {//登录
            type: 7, id: 8, msg: "Msg_Send_Login", encode: function (byte, data) {
                byte.writeString(data.type);// ANONYMOUS 匿名登录
                byte.writeString(data.openId);//微信openId
                byte.writeString(data.code);//短信验证码
                byte.writeString(data.longitude);//经度
                byte.writeString(data.latitude);//维度
            }
        },
        CreateRoom: {//创建房间
            type: 7, id: 0, msg: "Msg_Send_CreateRoom", encode: function (byte, data) {
                // 配置类型
                byte.writeString(data.profile);
                // 配置长度
                var len = data.options.length;
                byte.writeInt(len);

                // 配置数据
                for (var i = 0; i < len; i++) {
                    var key = data.options[i]['key'];
                    var value = data.options[i]['value'];
                    byte.writeString(key);
                    byte.writeString(value);
                }
            }
        },
        JoinRoom: {//加入房间
            type: 7, id: 6, msg: "Msg_Send_JoinRoom", encode: function (byte, data) {
                byte.writeString(data.roomId.toString());
            }
        },

        GameJoinRoom: {//游戏开始加入房间
            type: 1, id: 6, msg: "Msg_Send_GameJoinRoom", encode: function (byte, data) {
            }
        },
        ExitRoom: {// 请求退出房间
            type: 1, id: 23, msg: "Msg_Send_ExitRoom", encode: function (byte, data) {
                // 没有参数
            }
        },
    },
    recv: {
        recvTmp: {//模板
            type: 0, id: 0, msg: "Msg", decode: function (byte) {

            }
        },
        // todo 看一下这两个消息的区别
        DelRoom: {//删除房间GameDelRoom
            type: 7, id: 3, msg: "Msg_Recv_DelRoom", decode: function (byte) {
                var data = {};
                data.result = byte.readBoolean();
                return data;
            }
        },
        ExitRoom: {//删除房间返回
            type: 1, id: 3, msg: "Msg_Recv_ExitRoom", decode: function (byte) {
                var data = {};
                data.isEnd = byte.readBoolean();
                data.isStart = byte.readBoolean();
                return data;
            }
        },
        SysSet: {//系统设置
            type: 7, id: 24, msg: "Msg_Recv_SysSet", decode: function (byte) {
                var data = {};
                data.radio = byte.readString();
                data.notice = byte.readString();
                data.payInfo = byte.readString();
                data.agreement = byte.readString();
                return data;
            }
        },
        Login: {//登录返回
            type: 7, id: 10, msg: "Msg_Recv_Login",
            decode: function (byte) {
                var data = {};
                data.id = byte.readInt();
                data.name = byte.readString();
                data.openId = byte.readString();
                data.uuid = byte.readString();
                data.avatar = byte.readString();
                data.sex = byte.readInt();
                data.roomCheckId = byte.readString();
                data.gold = byte.readInt();
                data.loginToken = byte.readString();
                data.ip = byte.readString();
                return data;
            }
        },
        CreateRoom: {//创建房间
            type: 7, id: 1, msg: "Msg_Recv_CreateRoom", decode: function (byte) {
                var data = {};
                data.result = byte.readBoolean();
                data.roomId = byte.readString();
                return data;
            }
        },
        Notice: {//公告通知
            type: 7, id: 11, msg: "Msg_Recv_Notice", decode: function (byte) {
                var data ={};
                data.key = byte.readString();
                data.args = byte.readStringArray();
                data.type = byte.readInt();
                data.reboot = byte.readBoolean();
                return data;
            }
        },
        JoinRoom: {//加入房间
            type: 7, id: 7, msg: "Msg_Recv_JoinRoom", decode: function (byte) {
                var data = {};
                data.result = byte.readBoolean();
                return data;
            }
        },
        StartGame: {//开始游戏
            type: 7, id: 23, msg: "Msg_Recv_StartGame", decode: function (msg) {
            }
        },

        GameJoinRoom: {//游戏开始加入房间
            type: 1, id: 7, msg: "Msg_Recv_GameJoinRoom", decode: function (msg) {
            }
        },
    },
    getReceiveMsgStrByTypeAndID(type, id){
        var msg = null;
        for (var k in this.recv) {
            var item = this.recv[k];
            var itemType = item['type'];
            var itemId = item['id'];

            if (id == itemId && itemType == type) {
                msg = item['msg'];
                break;
            }
        }
        return msg;
    },
    getReceiveHandlerByTypeAndID(type, id){
        var msgObject = null;
        for (var k in this.recv) {
            var item = this.recv[k];
            var itemType = item['type'];
            var itemId = item['id'];

            if (id == itemId && itemType == type) {
                msgObject = item;
                break;
            }
        }
        return msgObject;
    },

    getSendMsgStrByTypeAndID(type, id){

    }
}